<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <script src="../js/flexible.js"></script>
    <title>兼职列表</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/job/style.css">
    <style>
    #pullUp {
        display: none !important;
    }
    </style>
</head>

<body>
    <div id="J_wrapper" class="container">
        <div id="scroller">
            <div id="pullDown">
                <span class="pullDownIcon"></span><span class="pullDownLabel">下拉刷新</span>
            </div>
            <div class="j_contents">
                <div class="j_content_wrap">
                </div>
                <div class="j_content_wrap">
                    <div class="nav">
                        <ul class="nav_box clearfix" style="padding-left:0;">
                            <li data-mark="0" class="active_line"><a href="javascript:;">全部</a></li>
                            <li data-mark="6"><a href="javascript:;">进行中</a></li>
                            <li data-mark="7"><a href="javascript:;">已完成</a></li>
                            <li data-mark="8"><a href="javascript:;">已结算</a></li>
                            <li data-mark="9"><a href="javascript:;">异常</a></li>
                        </ul>
                    </div>
                    <!-- 全部列表页面 -->
                    <div class="page_list">
                    </div>
                    <!--  end -->
                    <!--  进行中 -->
                    <div class="page_list ">
                    </div>
                    <!-- end -->
                    <!-- 已完成 -->
                    <div class="page_list ">
                    </div>
                    <!-- end -->
                    <!-- 已结算 -->
                    <div class="page_list ">
                    </div>
                    <!-- end -->
                    <!-- 异常 -->
                    <div class="page_list">
                    </div>
                    <!-- end -->
                </div>
            </div>
            <div id="pullUp">
                <span class="pullUpIcon"></span><span class="pullUpLabel">下拉加载</span>
            </div>
        </div>
    </div>
    <div class="tabs_wrap">
        <ul class="clearfix">
            <li class="active" data-mark="0"><a class="btn1" href="javascript:;">兼职</a></li>
            <li class="top_height" data-mark="10000"><a class="btn2" href="javascript:;">我的</a></li>
        </ul>
    </div>
</body>
<script src="../js/jquery.min.js"></script>
<script src="../js/fastclick.js"></script>
<script src="../js/scroll/iscroll.js"></script>
<script src="../js/scroll/scroll-init.js"></script>
<script src="../js/ajax/jsencrypt.js"></script>
<script src="../js/ajax/ajax.js"></script>
<script src="../js/main.js"></script>
<script type="text/javascript">
FastClick.attach(document.body);
var count_pages = 1;
//获取招聘中模块字符串
function str_state_1(data) {
    var arr = [];
    var created_yea = (data.t_created_at).substr(0, 10);
    var start_time = (data.t_start_time).substr(11, 5);
    var end_time = (data.t_end_time).substr(11, 5);
    arr.push('<div class="list_wrap">');
    arr.push('<div class="list_box">');
    arr.push('<h4 class="tit_box clearfix"><span class="tit1">' + data.c_name + '</span><span class="tit2">预计招聘' + data.t_number + '人</span></h4>');
    arr.push('<div class="txt_box">');
    arr.push('<p><i class="time_ico"></i>' + start_time + '-' + end_time + '</p>');
    arr.push('<p><i class="man_ico"></i>' + data.t_contacts + '</p>');
    arr.push('<p><i class="tel_ico"></i>' + data.t_phone + '</p>');
    arr.push('<p><i class="copy_ico"></i><span class="long-desc">车费:' + data.t_car_subsidy + '元'+'<span>用餐时间:' + data.t_dinner_time + '分钟</span>'+'<span>其他:' + data.t_other_subsidy + '元</span>'+'</span></p>');
    arr.push('</div>');
    arr.push('</div>');
    arr.push('</div>');
    arr.push('<div class="join_box clearfix">');
    arr.push('<span class="moneyT"><i class="time">￥' + data.t_price + '</i>/时</span>');
    arr.push('<a class="joinBtn j_join"  mange_id = ' + data.t_manage_id + ' task_id="' + data.t_id + '" enter_id="' + data.t_enterprise_id + '" href="javascript:;">加入兼职</a>');
    arr.push('</div>');
    arr.push('<div class="dates">' + created_yea + '</div>');
    return arr.join(' ');
};
//获取招聘结束在字符串
function str_state_2(data) {
    var arr = [];
    var start_time = (data.t_start_time).substr(11, 5);
    var end_time = (data.t_end_time).substr(11, 5);
    var created_yea = (data.t_created_at).substr(0, 10);
    arr.push('<div class="list_wrap">');
    arr.push('<div class="list_box">');
    arr.push('<h4 class="tit_box differ_tit clearfix"><span class="tit1">' + data.c_name + '</span><span class="tit2">预计招聘' + data.t_number + '人</span></h4>');
    arr.push('<div class="txt_box differ_p_color">');
    arr.push('<p><i class="time_ico"></i>' + start_time + '-' + end_time + '</p>');
    arr.push('<p><i class="man_ico"></i>' + data.t_contacts + '</p>');
    arr.push('<p><i class="tel_ico"></i>' + data.t_phone + '</p>');
    arr.push('<p><i class="copy_ico"></i><span class="long-desc">车费:' + data.t_car_subsidy + '元'+'<span>用餐时间:' + data.t_dinner_time + '分钟</span>'+'<span>其他:' + data.t_other_subsidy + '元</span>'+'</span></p>');
    arr.push('</div>');
    arr.push('</div>');
    arr.push('</div>');
    arr.push('<div class="join_box foot_border clearfix">');
    arr.push('<span class="moneyT moneyT2"><i class="time differ_txt">￥' + data.t_price + '</i>/时</span>');
    arr.push('<a class="joinBtn differ_bg1" href="javascript:;">招聘结束</a>');
    arr.push('</div>');
    arr.push('<div class="dates">' + created_yea + '</div>');
    return arr.join('');
};
//获取已参加在字符串
function str_state_3(data) {
    var arr = [];
    var start_time = (data.t_start_time).substr(11, 5);
    var end_time = (data.t_end_time).substr(11, 5);
    var created_yea = (data.t_created_at).substr(0, 10);
    arr.push('<div class="list_wrap">');
    arr.push('<div class="list_box">');
    arr.push('<h4 class="tit_box clearfix"><span class="tit1">' + data.c_name + '</span><span class="tit2">预计招聘' + data.t_number + '人</span></h4>');
    arr.push('<div class="txt_box">');
    arr.push('<p><i class="time_ico"></i>' + start_time + '-' + end_time + '</p>');
    arr.push('<p><i class="man_ico"></i>' + data.t_contacts + '</p>');
    arr.push('<p><i class="tel_ico"></i>' + data.t_phone + '</p>');
    arr.push('<p><i class="copy_ico"></i><span class="long-desc">车费:' + data.t_car_subsidy + '元'+'<span>用餐时间:' + data.t_dinner_time + '分钟</span>'+'<span>其他:' + data.t_other_subsidy + '元</span>'+'</span></p>');
    arr.push('</div>');
    arr.push('</div>');
    arr.push('</div>');
    arr.push('<div class="join_box clearfix">');
    arr.push('<span class="moneyT"><i class="time">￥' + data.t_price + '</i>/时</span>');
    arr.push('<a class="joinBtn differ_bg2" href="javascript:;">已参加</a>');
    arr.push('</div>');
    arr.push('<div class="dates">' + created_yea + '</div>');
    return arr.join(' ');
};
//全部内容模板

//签到的模板
function state_1(data) {
    var arr = [];
    var created_yea = (data.t_created_at).substr(0, 10);
    arr.push('<div class="list_wrap">');
    arr.push('<div class="list_box">');
    arr.push('<h4 class="tit_box clearfix"><span class="tit1">' + data.c_name + '</span><span class="tit2">预计招聘' + data.t_number + '人</span></h4>');
    arr.push('<div class="txt_box">');
    arr.push('<p><i class="time_ico"></i>' + data.t_start_time + '-' + data.t_end_time + '</p>');
    arr.push('<p><i class="man_ico"></i>' + data.t_contacts + '</p>');
    arr.push('<p><i class="tel_ico"></i>' + data.t_phone + '</p>');
    arr.push('<p><i class="copy_ico"></i><span class="long-desc">车费:' + data.t_car_subsidy + '元'+'<span>用餐时间:' + data.t_dinner_time + '分钟</span>'+'<span>其他:' + data.t_other_subsidy + '元</span>'+'</span></p>');
    arr.push('</div></div></div>');
    arr.push('<div class="join_box clearfix">');
    arr.push('<span class="moneyT"><i class="time">￥' + data.t_price + '</i>/时</span>');
    arr.push('<a class="j_common j_sign_in joinBtn bg_gre" id=' + data.t_id + ' href="javascript:;">签到</a>');
    arr.push('</div>');
    arr.push('<div class="dates">' + created_yea + '</div>');
    return arr.join(' ');
};

//已完成
function state_3(data) {
    var arr = [];
    var created_yea = (data.t_created_at).substr(0, 10);
    arr.push('<div class="list_wrap">');
    arr.push('<div class="list_box">');
    arr.push('<h4 class="tit_box clearfix"><span class="tit1">' + data.c_name + '</span><span class="tit2">预计招聘' + data.t_number + '人</span></h4>');
    arr.push('<div class="txt_box">');
    arr.push('<p><i class="time_ico"></i>' + data.t_start_time + '-' + data.t_end_time + '</p>');
    arr.push('<p><i class="man_ico"></i>' + data.t_contacts + '</p>');
    arr.push('<p><i class="tel_ico"></i>' + data.t_phone + '</p>');
    arr.push('<p><i class="copy_ico"></i><span class="long-desc">车费:' + data.t_car_subsidy + '元'+'<span>用餐时间:' + data.t_dinner_time + '分钟</span>'+'<span>其他:' + data.t_other_subsidy + '元</span>'+'</span></p>');
    arr.push('</div></div></div>');
    arr.push('<div class="join_box clearfix">');
    arr.push('<span class="moneyT"><i class="time">￥' + data.t_price + '</i>/时</span>');
    arr.push('<a class="j_complete joinBtn differ_bg2"task_id=' + data.task_id + ' href="javascript:;">已完成</a></div>');
    arr.push('<div class="dates">' + created_yea + '</div>');
    return arr.join(' ');
};

//签退
function state_4(data) {
    var arr = [];
    var created_yea = (data.t_created_at).substr(0, 10);
    arr.push('<div class="list_wrap">');
    arr.push('<div class="list_box">');
    arr.push('<h4 class="tit_box clearfix"><span class="tit1">' + data.c_name + '</span><span class="tit2">预计招聘' + data.t_number + '人</span></h4>');
    arr.push('<div class="txt_box">');
    arr.push('<p><i class="time_ico"></i>' + data.t_start_time + '-' + data.t_end_time + '</p>');
    arr.push('<p><i class="man_ico"></i>' + data.t_contacts + '</p>');
    arr.push('<p><i class="tel_ico"></i>' + data.t_phone + '</p>');
    arr.push('<p><i class="copy_ico"></i><span class="long-desc">车费:' + data.t_car_subsidy + '元'+'<span>用餐时间:' + data.t_dinner_time + '分钟</span>'+'<span>其他:' + data.t_other_subsidy + '元</span>'+'</span></p>');
    arr.push('</div></div></div>');
    arr.push('<div class="join_box clearfix">');
    arr.push('<span class="moneyT"><i class="time">￥' + data.t_price + '</i>/时</span>');
    arr.push('<a class="j_sign_out joinBtn differ_bg3"  id=' + data.t_id + ' href="javascript:;">签退</a></div>');
    arr.push('<div class="dates">' + created_yea + '</div>');
    return arr.join(' ');
};

//异常
function state_5(data) {
    var arr = [];
    var created_yea = (data.t_created_at).substr(0, 10);
    arr.push('<div class="list_wrap">');
    arr.push('<div class="list_box">');
    arr.push('<h4 class="tit_box differ_tit clearfix"><span class="tit1">' + data.c_name + '</span><span class="tit2">预计招聘' + data.t_number + '人</span></h4>');
    arr.push('<div class="txt_box differ_p_color">');
    arr.push('<p><i class="time_ico"></i>' + data.t_start_time + '-' + data.t_end_time + '</p>');
    arr.push('<p><i class="man_ico"></i>' + data.t_contacts + '</p>');
    arr.push('<p><i class="tel_ico"></i>' + data.t_phone + '</p>');
    arr.push('<p><i class="copy_ico"></i><span class="long-desc">车费:' + data.t_car_subsidy + '元'+'<span>用餐时间:' + data.t_dinner_time + '分钟</span>'+'<span>其他:' + data.t_other_subsidy + '元</span>'+'</span></p>');
    arr.push('</div></div></div>');
    arr.push('<div class="join_box foot_border clearfix">');
    arr.push('<span class="moneyT moneyT2"><i class="time differ_txt">￥' + data.t_price + '</i>/时</span>');
    arr.push('<a class="joinBtn differ_bg1 red_color" href="javascript:;">异常</a></div>');
    arr.push('<div class="dates">' + created_yea + '</div>');
    return arr.join(' ');
};

//已结算
function state_6(data) {
    var arr = [];
    var created_yea = (data.t_created_at).substr(0, 10);
    arr.push('<div class="list_wrap">');
    arr.push('<div class="list_box">');
    arr.push('<h4 class="tit_box differ_tit clearfix"><span class="tit1">' + data.c_name + '</span><span class="tit2">预计招聘' + data.t_number + '人</span></h4>');
    arr.push('<div class="txt_box differ_p_color">');
    arr.push('<p><i class="time_ico"></i>' + data.t_start_time + '-' + data.t_end_time + '</p>');
    arr.push('<p><i class="man_ico"></i>' + data.t_contacts + '</p>');
    arr.push('<p><i class="tel_ico"></i>' + data.t_phone + '</p>');
    arr.push('<p><i class="copy_ico"></i><span class="long-desc">车费:' + data.t_car_subsidy + '元'+'<span>用餐时间:' + data.t_dinner_time + '分钟</span>'+'<span>其他:' + data.t_other_subsidy + '元</span>'+'</span></p>');
    arr.push('</div></div></div>');
    arr.push('<div class="join_box foot_border clearfix">');
    arr.push('<span class="moneyT moneyT2"><i class="time differ_txt">￥' + data.t_price + '</i>/时</span>');
    arr.push('<a class="joinBtn differ_bg11" href="javascript:;">已结算' + data.t_priceall + '元</a></div>');
    arr.push('<div class="dates">' + created_yea + '</div>');
    return arr.join(' ');
};



function pullUpAction() {
    var _key;
    if (curNav == 0) {
        _key = type + "main";
    } else {
        _key = type;
    }
    if (!countObj[_key]) {
        countObj[_key] = 1;
    } else {
        countObj[_key]++;
    }

    if (!!stateObj[_key]) {
        return false;
    }

    if (curNav == 0) {

        start.postAjaxReq({
            param: {
                "id": manageId,
                "type": userType,
                "page_size": 5,
                "page": countObj[_key]
            },
            type: "GET",
            url: "/task/getTaskList",
            success: function(data) {
                var meta = data.result.meta;
                var html = '',
                    now, obj = data.result.data;
                if (obj.length > 0) {
                    for (var i = 0; i < obj.length; i++) {
                        now = obj[i];
                        if (!!now.t_status && now.t_status_id == 1) {
                            html += str_state_3(now); //已参加
                        } else if (now.t_status_id == 1) {
                            html += str_state_1(now); //招聘中 显示加入兼职
                        } else if (now.t_status_id == 10) {
                            html += str_state_2(now); //招聘结束
                        }
                    }
                    $(".j_content_wrap:visible").append(html);
                } else {
                    if (countObj[_key] == 1 && obj.length == 0) {
                        html = shoNoData();
                        stateObj[_key] = true;
                    }
                    $(".j_content_wrap:visible").append(html);
                    return false;
                }
                if (meta.current_page == meta.total_pages) {
                    showFadeData();
                    stateObj[_key] = true;
                }
                myScroll.refresh();
            },
            errorCb: function(data) {}
        });
    } else {
        start.postAjaxReq({
            param: {
                "page_size": 10,
                "page": countObj[_key],
                'worker_id': manageId,
                'status': $(".nav").find(".active_line").attr("data-mark")
            },
            type: "GET",
            url: "/task/getMyTaskList",
            success: function(data) {
                var meta = data.result.meta;
                var html = '',
                    now,
                    obj = data.result.data;
                if (obj.length > 0) {
                    for (var j = 0; j < obj.length; j++) {
                        now = obj[j];
                        // 0全部 6进行中 7已完成 8已结算 9异常
                        if (now.t_status == 5) {
                            html += state_1(now); //渲染签 到模块
                        } else if (now.t_status == 6) {
                            html += state_4(now); //渲染签退模块
                        } else if (now.t_status == 7) {
                            html += state_3(now); //渲染已完成模块
                        } else if (now.t_status == 8) {
                            html += state_6(now); //渲染已结算模块
                        } else if (now.t_status == 9) {
                            html += state_5(now); //渲染异常模块
                        }
                    }
                    $("#pullUp").show();
                    $(".page_list:visible").append(html);
                } else if (countObj[_key] == 1 && obj.length == 0) {
                    html = shoNoData();
                    stateObj[_key] = true;
                    $(".page_list:visible").append(html);
                    return false;
                }

                if (obj.length == 0) {
                    showFadeData();
                    //alert("已经加载完毕");
                    stateObj[_key] = true;
                }
                myScroll.refresh();
            },
            errorCb: function(data) {
                showFadeData();
                stateObj[_key] = true;
            }
        });
    }
}
//兼职 和我的选项卡
var curNav = 0; //判断当前一级导航的位置
var subNav = 0; //判断当前二级导航的位置
var object = {}; //用于仅限一次点击使用;
var type = ""; //用于保存当前的类型
var countObj = {}; //用于统计请求页数的对象
var stateObj = {};
var manageId = 1;
var userType = 1;
var isFirst = true; //判断是否是第一次

if (GetQueryString("userId")) {
    manageId = GetQueryString("userId"); //获取当前会话的id
}
if (GetQueryString("type")) {
    userType = GetQueryString("userType"); //获取当前的用户类型
}


//给一级导航绑定事件
$(".tabs_wrap").delegate("li", "click", function() {
    var now = $(this);
    type = now.attr("data-mark");

    curNav = now.index();
    localStorage.setItem("cur_index", curNav);

    now.addClass("active").siblings().removeClass("active");
    $(".j_contents").find(".j_content_wrap").eq(curNav).show().siblings().hide();

    if (!object[type]) {
        if (curNav == 0) {
            pullUpAction();
            isFirst = false;
        } else {
            if (!isFirst) {
                $(".nav").find("li").eq(0).trigger("click");
            } else {
                isFirst = false;
            }

        }

        object[type] = true;
    }

});

//给二级导航添加绑定事件
$(".nav").delegate('li', 'click', function() {
    var now = $(this);
    type = now.attr("data-mark");
    subNav = now.index();
    localStorage.setItem("sub_index", subNav);
    now.addClass("active_line").siblings().removeClass("active_line");
    $(".page_list").eq(subNav).show().siblings(".page_list").hide();
    if (!object[type + "sub"]) {
        pullUpAction();
        object[type + "sub"] = true;
    }
});

if (localStorage.getItem("cur_index")) {
    curNav = localStorage.getItem("cur_index");
    if (curNav == 0) {
        $(".tabs_wrap").find("li").eq(curNav).trigger('click');
    } else {
        $(".tabs_wrap").find("li").eq(curNav).trigger('click');
        if (localStorage.getItem("sub_index")) {
            subNav = localStorage.getItem("sub_index");
            $(".nav").find("li").eq(subNav).trigger("click");
        }
    }

} else {
    $(".tabs_wrap").find("li").eq(0).trigger('click');
}
</script>

</html>
